<?php

/**
 * user actions.
 *
 * @package    maximous
 * @subpackage user
 * @author     Mina.Gerges.Wadea
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class userActions extends MaxFrontendActions
{

    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request)
    {
        //$this->forward('default', 'module');
    }

    /**
     * register action
     * @param sfWebRequest $request 
     */
    public function executeRegister(sfWebRequest $request)
    {
        $form = new RegisterUserForm(null, array('i18n' => $this->i18n));
        if ($request->isMethod(sfRequest::POST))
        {
            $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
            if ($form->isValid())
            {
                $form->save();
                // to show success mesage redirect to another action
                // use redirect inestead of forward to prevent sending the data aagain if user refrash page
                $this->getUser()->setFlash('registerDone', true);
                $this->redirect('RegisterDone');
            }
        }
        $this->form = $form;
    }

    public function executeRegisterDone()
    {
        // go to 404page if user try to open this page without register
        if(!$this->getUser()->hasFlash('registerDone'))
        {
            $this->redirect('HomePage');
        }
    }

}
